package com.xuan.chatroom.controller;


import com.xuan.chatroom.constants.Constant;
import com.xuan.chatroom.model.AddRequest;
import com.xuan.chatroom.model.Friend;
import com.xuan.chatroom.model.Result;
import com.xuan.chatroom.model.User;
import com.xuan.chatroom.service.FriendService;
import com.xuan.chatroom.utils.JwtUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpSession;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/friend")
public class FriendController {
    @Autowired
    private FriendService friendService;

    @RequestMapping("/getFriendList")
    public Result getFriendList(@RequestHeader(Constant.USER_TOKEN_HEADER) String token) {
        // 1. 从 token 中获取 userId
        int userId = JwtUtil.getIdFromToken(token);

        // 2. 根据当前用户id 查询好友信息
        List<Friend> friendList = friendService.queryFriendListByUserID(userId);
        return Result.success(friendList);
    }

    @RequestMapping("/getAddRequests")
    public Result getAddRequests(@RequestHeader(Constant.USER_TOKEN_HEADER) String token) {
        // 从 token 中获取用户 id
        int id = JwtUtil.getIdFromToken(token);

        return friendService.getAddRequests(id);
    }


}
